/**  
 * All rights Reserved, Designed By Android_Robot   
 * @Title:  MalfunctionAdapter.java   
 * @Package com.jiyi.adapter   
 * @Description:    TODO(用一句话描述该文件做什么)   
 * @author: HYM     
 * @date:   2017-9-4 上午10:28:38   
 * @version V1.0     
 */
package com.jiyi.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.jiyi.bean.maintenance.RepairProgressBean;
import com.swift.maintenance.R;

import java.util.List;

/**
 * @ClassName: MalfunctionAdapter
 * @Description:TODO(这里用一句话描述这个类的作用)
 * @author: HYM
 * @date: 2017-9-4 上午10:28:38
 * 
 */
public class RepairProgressAdapter extends BaseAdapter {
	private List<RepairProgressBean> dataList;
	private Context mContext;
	int parentType, parentPosition;

	public RepairProgressAdapter(Context context,
			List<RepairProgressBean> data, int type, int position) {
		this.mContext = context;
		this.dataList = data;
		this.parentType = type;
		this.parentPosition = position;
	}

	@Override
	public int getCount() {
		if (dataList != null) {
			return dataList.size();
		} else {
			return 0;
		}
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		final RepairProgressBean item = dataList.get(position);

		ViewHolder viewHolder;
		if (convertView == null) {

			viewHolder = new ViewHolder();
			convertView = LayoutInflater.from(mContext).inflate(
					R.layout.item_repair_comment, parent, false);
			viewHolder.tvCommons = (TextView) convertView
					.findViewById(R.id.tvCommons);
			viewHolder.ivIcon = (ImageView) convertView
					.findViewById(R.id.ivIcon);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		if (dataList.size() == 1) {
			viewHolder.ivIcon.setImageResource(R.mipmap.icon_progress);
		}
		else if (dataList.size() == 2) {
			if (position == 0) {
				viewHolder.ivIcon.setImageResource(R.mipmap.icon_down_progress);
			}
			else {
				viewHolder.ivIcon.setImageResource(R.mipmap.icon_up_progress);
			}
		}
		else {
			if (position == 0) {
				viewHolder.ivIcon.setImageResource(R.mipmap.icon_down_progress);
			}
			else if (position == dataList.size()-1) {
				viewHolder.ivIcon.setImageResource(R.mipmap.icon_up_progress);
			}
			else {
				viewHolder.ivIcon.setImageResource(R.mipmap.icon_middle_progress);
			}
		}
		viewHolder.tvCommons.setText(item.getPlan());

		return convertView;
	}

	class ViewHolder {
		private TextView tvCommons;
		private ImageView ivIcon;
	}

	@Override
	public Object getItem(int position) {
		return dataList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
}
